package jp.aist.gtrc.plus.admission.EDF.simulation;

import jp.aist.gtrc.plus.admission.EDF.*;

public   class JobInfo {
   public static final int WAITING = 0;
   public static final int EXECUTING = 1;
   public static final int DONE = 2;

   public int arrivalTime;
   public int startTime;
   public int stopTime;
   public JobArray jobArray; 
   public CPU cpu;
   private int state;

   public JobInfo(int arrivalTime, JobArray jobArray) {
      this.arrivalTime = arrivalTime;
      this.startTime = Integer.MAX_VALUE;
      this.stopTime = Integer.MAX_VALUE;
      this.jobArray = jobArray;
      this.state = JobInfo.WAITING;
   }

   public void executeOn(CPU cpu,int startTime) {
      if (this.state == JobInfo.EXECUTING) 
         throw new RuntimeException("Redispatch job"); 
      this.cpu = cpu;
      this.state = JobInfo.EXECUTING;
      this.startTime = startTime;
   }

   public CPU getExecutingCPU() {
      return this.cpu;
   }

   public void done(int stopTime) {
      this.cpu = null;
      this.state = JobInfo.DONE;
      this.stopTime = stopTime;
   }

   public boolean isExecuting() {
      return (this.state == JobInfo.EXECUTING);
   }

   public boolean isWaiting() {
      return (this.state == JobInfo.WAITING); 
   }

   public boolean isDone() {
      return (this.state == JobInfo.DONE);
   }

   public int getState() {
      return this.state;
   }

}

